using System;
using System.Collections.Generic;
using System.Text;
using LiveStock.dataAccess;
using LiveStock.RssObjects;

namespace LiveStock.Evaluation
{
    class YahooEvaluation : IEvaluation
    {
        public YahooEvaluation()
        {

        }

        public List<NewsItem> getNewsItems(string stockSymbol)
        {
            List<NewsItem> theNewsItemList = new List<NewsItem>();
            EvaluationSources.EvaluationSourcesDataTable yahooSourcesDataTable = EvaluationSourcesData.EvaluationSourceGetByName("Yahoo Finance Headline Search");
            if (yahooSourcesDataTable.Rows.Count > 0)
            {
                RssDataSet yahooRssDataSet = RssReader.ProcessRSSItem(yahooSourcesDataTable[0].URL + stockSymbol);
                RssDataSet.itemRow yahooRssItemRow;
                for (int i = 0; i < yahooRssDataSet.item.Rows.Count; i++)
                {
                    yahooRssItemRow = yahooRssDataSet.item[i];
                    NewsItem newsItem = new NewsItem(
                        yahooRssItemRow.title, yahooRssItemRow.description, yahooRssItemRow.link, Convert.ToDateTime(yahooRssItemRow.pubDate), 
                        yahooSourcesDataTable[0].EvaluationSourceID
                        );
                    theNewsItemList.Add(newsItem);
                }
            }

            return theNewsItemList;
        }
    }
}
